﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.FireProjects.Model;
using Yipusoft.FireProjects.BLL;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using Yipusoft.SixAcquaint.BLL;
using Yipusoft.SixAcquaint.Model;
using Yipusoft.Vehicle.Model;
using Yipusoft.Account.BLL;
using Yipusoft.Vehicle.BLL;

public partial class BasicBase_FireProject_FireProjectView1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        BindProject();
    }

    private void BindProject()
    {
        if (!Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "201300") && !Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "201306"))
        {
            Response.Write("<script>alert('没有权限！');window.close();</script>");
            return;
        }
        string ID = Request.QueryString["ID"];
        FireProjectInfo info = FireProject.getFireproject(new Guid(ID));
        if (info.ClassID.Length > 0)
        {
            lblClass.Text = CodeItem.GetCodeItem(info.ClassID).ItemName;
        }
        if (info.TypeID.Length > 0)
        {
            lblType.Text = CodeItem.GetCodeItem(info.TypeID).ItemName;
        }
        if (info.TypeID == "MHJYYALB0300")
        {
            KeyUnitTr.Visible = true;
            if (info.ProjectID != Guid.Empty)
            {
                KeyUnitInfo keyUnit = KeyUnit.GetKeyUnitInfoByID(info.UnitId.ToString());
                if (keyUnit != null)
                {
                    HypKeyUnitName.Text = keyUnit.UnitName;
                    HypKeyUnitName.NavigateUrl = "../KeyUnit/KeyUnitView.aspx?id=" + info.UnitId;
                }
                else
                {
                    HypKeyUnitName.Text = "此重点单位未找到！请重新添加重点单位。";
                }
            }
            else
            {
                KeyUnitTr.Visible = false;
            }
        }
        else
        {
            KeyUnitTr.Visible = false;
        }
        lblDepartment.Text = info.DepartmentName;
        lblDescription.Text = UserFun.TextToHtml(info.Description);
        lblProjectName.Text = info.ProjectName;
        lblSetTime.Text = info.SetTime.ToString();
        lblUpdateTime.Text = info.UpdateTime.ToString();
        lblUpdateAD.Text = "";
        lblSetAD.Text = "";
        lbtViewWord.NavigateUrl = "WordFile/" + info.WordName;

        //车辆
        string VehicleWhere = " ProjectID='" + info.ProjectID + "' ";
        List<FireProjectVehicleInfo> Vehiclelist = FireProjectVehicles.GetList(VehicleWhere);
        List<Guid> VehicleIds = new List<Guid>();
        foreach (FireProjectVehicleInfo vehicle in Vehiclelist)
        {
            VehicleIds.Add(vehicle.VehicleId);
        }
        gv.DataSource = VehicleIds;
        gv.DataBind();
    }
    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = ((e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");

            Guid id = new Guid(e.Row.DataItem.ToString());
            VehicleInfo info = Vehicle.GetDetail(id);
            if (info != null)
            {
                //车辆名称
                HyperLink VehicleName = e.Row.FindControl("VehicleName") as HyperLink;
                VehicleName.Text = info.VehicleName;
                VehicleName.NavigateUrl = "../Vehicle/VehicleView.aspx?id=" + id;

                Label lblclass = e.Row.FindControl("lblclass") as Label;
                lblclass.Text = GetType(info.VehicleClass);

                Label lblType = e.Row.FindControl("lblType") as Label;
                lblType.Text = GetCodeItem("XFZBLB", info.VehicleClass);

                Label lbldepartmentName = e.Row.FindControl("lbldepartmentName") as Label;
                lbldepartmentName.Text = GetDepartmentName(info.DepartmentID);
            }



        }
    }
    public string GetType(string itemID)
    {
        CodeItemInfo Item = CodeItem.GetCodeItem(itemID, "XFZBLB");
        CodeItemInfo Pitem = CodeItem.GetCodeItem(Item.ParentID, "XFZBLB");
        return Pitem.ItemName;
    }
    protected string GetDepartmentName(string data)
    {
        return Department.GetDepartment(data).FullName;
    }

    public string GetCodeItem(string GroupID, string deviceClass)
    {
        Yipusoft.Common.Model.CodeItemInfo info = CodeItem.GetCodeItem(deviceClass, GroupID);
        return info != null ? info.ItemName : "";
    }
}
